//
//  MyTabBarController.swift
//  NewsT
//
//  Created by Canny on 2018/3/1.
//  Copyright © 2018年 WK. All rights reserved.
//

import UIKit

class MyTabBarController: UITabBarController {

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        print(tabBar.subviews)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        let tabbar = UITabBar.appearance()
        tabbar.tintColor = UIColor(red:245/255.0 , green:90/255.0 , blue:93/255.0 ,alpha:1.0)
        

        //添加子控制器
        addChildViewController()
        
        
    }
    
    func addChildViewController()  {
        setChildViewController(HomeViewController(), title: "首页", imageName: "home_tabbar_32x32_", selectedImgeName: "home_tabbar_press_32x32_")
        setChildViewController(VideoViewController(), title: "视频", imageName: "video_tabbar_32x32_", selectedImgeName: "video_tabbar_press_32x32_")
        setChildViewController(HuoshanViewController(), title: "小视频", imageName: "huoshan_tabbar_32x32_", selectedImgeName: "huoshan_tabbar_press_32x32_")
        setChildViewController(MineViewController(), title: "我的", imageName: "mine_tabbar_32x32_", selectedImgeName: "mine_tabbar_press_32x32_")
        
        setValue(MyTabBar(), forKey: "tabBar")
        
    }

    /*
     * 初始化
     */
    func setChildViewController(_ childController: UIViewController , title: String , imageName: String, selectedImgeName: String)  {
        //设置 tabbar 文字和图片
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: selectedImgeName)
//        childController.tabBarItem.title = title
        childController.title=title
        //添加导航控制器为 TabBarController 的子控制器
        let navVc = MyNavigationController(rootViewController: childController)
//        //设置标题
//        navVc.navigationItem.title = title
        addChildViewController(navVc)
        
    }
    
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
